package servlet;

import util.JdbcUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class InboundreUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int inid= Integer.parseInt(request.getParameter("inid"));
        int wid= Integer.parseInt(request.getParameter("wid"));
        String type = request.getParameter("type");
        String rname = request.getParameter("rname");
        Double price=Double.parseDouble(request.getParameter("price"));
        Double number=Double.parseDouble(request.getParameter("number"));
        String time = request.getParameter("time");
        String sql ="UPDATE record_in set wid=?,type=?,rname =?,price=?,number=?,time=? WHERE inid=?";
        try {
            PreparedStatement ps = JdbcUtil.getConnection().prepareStatement(sql);
            ps.setInt(1,wid);
            ps.setString(2,type);
            ps.setString(3,rname);
            ps.setDouble(4,price);
            ps.setDouble(5,number);
            ps.setString(6,time);
            ps.setInt(7,inid);
            int up = ps.executeUpdate();
            request.getRequestDispatcher("inbound.jsp").forward(request, response);

        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }
}
